import { reactive } from 'vue'
import { getToken } from '@/utils/token-cache'
import Request from '@/apis/index'
const style = require('@/utils/style.js')
const baseUrl = 'http://localhost:3008'
export const setting = reactive({
    language: 'zh_CN',
    style,
    height: 660,
    menubar: false, // 禁用菜单栏
    plugins: 'link image media table lists fullscreen quickbars',
    toolbar: `bold italic underline strikethrough forecolor backcolor link autolink
          | alignleft aligncenter alignright alignjustify outdent indent bullist numlist
          | formatselect fontselect fontsizeselect lineheight
          | blockquote subscript superscript removeformat image media table
          | hr insertdatetime preview code codesample visualblocks searchreplace
          | undo redo fullscreen`,
    toolbar_mode: 'sliding',
    placeholder: '请输入正文',
    branding: false,
    autosave_ask_before_unload: false,
    font_formats:
        '微软雅黑=Microsoft YaHei,Helvetica Neue,PingFang SC,sans-serif;' +
        '苹果苹方=PingFang SC,Microsoft YaHei,sans-serif;宋体=simsun,serif;仿宋体=FangSong,serif;黑体=SimHei,sans-serif;' +
        'Arial=arial,helvetica,sans-serif;Arial Black=arial black,avant garde;Book Antiqua=book antiqua,palatino;' +
        'Comic Sans MS=comic sans ms,sans-serif;Courier New=courier new,courier;Georgia=georgia,palatino;' +
        'Helvetica=helvetica;Impact=impact,chicago;Symbol=symbol;Tahoma=tahoma,arial,helvetica,sans-serif;' +
        'Terminal=terminal,monaco;Times New Roman=times new roman,times;Verdana=verdana,geneva;Webdings=webdings;' +
        'Wingdings=wingdings,zapf dingbats;' +
        '知乎配置=BlinkMacSystemFont, Helvetica Neue, PingFang SC, Microsoft YaHei, ' +
        'Source Han Sans SC, Noto Sans CJK SC, WenQuanYi Micro Hei, sans-serif;' +
        '小米配置=Helvetica Neue,Helvetica,Arial,Microsoft Yahei,Hiragino Sans GB,Heiti SC,WenQuanYi Micro Hei,sans-serif',
    fontsize_formats: '12px 14px 16px 18px 24px 36px 48px 56px 72px',
    formats: {
        h1: { block: 'h1', classes: 'aiming-point' },
        h2: { block: 'h2', classes: 'aiming-point' },
        h3: { block: 'h3', classes: 'aiming-point' },
        h4: { block: 'h4', classes: 'aiming-point' },
        h5: { block: 'h5', classes: 'aiming-point' }
    },
    content_style: `body::-webkit-scrollbar {
        width: 8px;
        height: 8px;
      }
      body::-webkit-scrollbar-thumb {
        background-color: #c0c4cc;
        border: 3px solid transparent;
        border-radius: 7px;
      }
      body::-webkit-scrollbar-thumb:hover {
        background-color: #ededed;
      }
      img{
        display: block;
        margin: auto;
      }
      body::-webkit-scrollbar-track {
      /*滚动条里面轨道*/
        box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
        border-radius: 6px;
        background: #ededed;
      }` + style,
    /**
     * @desc:图片上传
     */
    images_upload_handler: (blobInfo: { blob: () => any }, progress: (res: number) => {}) => {
        return new Promise((reslove, resject) => {
            if (blobInfo.blob().size / 1024 / 1024 > 5) {
                resject('上传失败，图片大小请控制在 5M 以内')
            } else {
                const data = new FormData()
                data.append('file', blobInfo.blob())
                progress(0)
                Request.post({
                    url: '/upload',
                    data: data
                }).then((res) => {
                    if (res && res.url) {
                        progress(100)
                        reslove(res.url.replace('_thumb', ''))
                    } else {
                        resject('上传失败')
                    }
                })
            }
        })
    }
})